package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.daoImpl.ProfileDAO;
import com.ecable.util.UtilConstants;

public class DeleteOperatorAction extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RequestDispatcher rd = null;

		boolean flag = false;
		String path = "";
		String ch[] = request.getParameterValues("ch");
		try {
			for (int i = 0; i < ch.length; i++) {
				System.out.println(ch[i]);
				flag = new ProfileDAO().deleteOperator(Integer
						.parseInt(ch[i]));
			}
			}
			catch(Exception e){System.out.println(e);}
			try {
		if (flag) {
				request.setAttribute("status", UtilConstants._REQUEST_OPERATOR_DELETE);
				path = UtilConstants._DISPLAY_OPERATOR_ACTION;

			} else {
				request.setAttribute("status",
						UtilConstants._REQUEST_OPERATOR_DELETE_FAIL);
				path = UtilConstants._DISPLAY_OPERATOR_ACTION;
			}

		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("status", UtilConstants._REQUEST_OPERATOR_DELETE_FAIL);
			path = UtilConstants._DISPLAY_OPERATOR_ACTION;
		}

		rd = request.getRequestDispatcher(path);
		rd.forward(request, response);

	}

}
